package zhongbo.java.air.dictionary.web.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.mapper.AlertZoneMapper;
import zhongbo.java.air.dictionary.model.AlertZone;
import zhongbo.java.air.dictionary.service.IAlertZoneService;

import java.util.List;

@RestController
@Api(tags = "警戒区域相关")
//@ApiModel("/api/alertZone")
@RequestMapping("api/alertZone")
public class AlertZoneController {
    @Autowired
    private IAlertZoneService alertZoneService;


    @ApiOperation("新增一个警戒区域")
    @PostMapping("/addAlertZone")
    public ResultVo<String> addAlertZone(@RequestBody AlertZone alertZone) {
        String add = alertZoneService.addAlertZone(alertZone);
        if (StrUtil.isNotBlank(add)) {
            return ResultVo.ok(add);
        }
        return ResultVo.error("新增失败");
    }
    @ApiOperation("查询一个警戒区域")
    @GetMapping("/getAlertZone")
    public ResultVo<AlertZone> getAlertZone(@RequestParam(defaultValue = "1") String alertZoneId) {
        AlertZone alertZone = alertZoneService.getAlertZoneById(alertZoneId);
        return ResultVo.ok(alertZone);
    }

    @ApiOperation("删除一个警戒区域")
    @DeleteMapping("/deleteAlertZone")
    public ResultVo<Integer> deleteAlertZone(@RequestParam(defaultValue = "1") String alertZoneId) {
        int delete = alertZoneService.deleteAlertZone(alertZoneId);
        return ResultVo.ok(delete);
    }

    @ApiOperation("修改一个警戒区域")
    @PutMapping("/updateAlertZone")
    public ResultVo<AlertZone> updateAlertZone(@RequestBody AlertZone alertZone) {
        AlertZone updateAlertZone = alertZoneService.updateAlertZone(alertZone);
        if (updateAlertZone != null) {
            return ResultVo.ok(updateAlertZone);
        }
        return ResultVo.error("修改失败");
    }

    @ApiOperation("获取所有警戒区域列表")
    @GetMapping("/getAlertZoneAll")
    public ResultVo<List<AlertZone>> alertZoneList() {
        List<AlertZone> alertZoneList = alertZoneService.getaAlertZoneAll();
        return ResultVo.ok(alertZoneList);
    }

    @ApiOperation("分页所有警戒区域")
    @GetMapping("/pageAlertZoneAll")
    public ResultVo<PageVo<AlertZone>> page(@RequestParam(required = false) String zoneCode,
                                          @RequestParam(defaultValue = "1") Integer pageNumber,
                                          @RequestParam(defaultValue = "1") Integer pageSize) {
        PageVo<AlertZone> page = alertZoneService.page(zoneCode,pageNumber,pageSize);
        return ResultVo.ok(page);
    }
}
